package org.example.Polls;

import java.util.List;
import java.util.Set;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioButton;
import android.widget.TextView;

public class ItemAdapter extends BaseAdapter implements OnClickListener {
	private Context context;
	
	private List<PollItem> itemList;
	
	public ItemAdapter(Context context, List<PollItem> itemList) {
		this.context = context;
		this.itemList = itemList;
	}

	public int getCount() {
		return itemList.size();
	}

	public Object getItem(int position) {
		return itemList.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup viewGroup) {
		PollItem entry = itemList.get(position);
		if(convertView == null) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.item_row, null);
		}
		
		TextView itemName = (TextView) convertView.findViewById(R.id.item_row_item_name);
		itemName.setText(entry.getText());
		
		RadioButton chosen = (RadioButton) convertView.findViewById(R.id.item_row_item_radio_button);
		chosen.setFocusableInTouchMode(false);
		chosen.setFocusable(false);
		chosen.setOnClickListener(this);
		chosen.setTag(entry);
		
		return convertView;
	}
	
	public void onClick(View view) {
		PollItem entry = (PollItem) view.getTag();
		// TODO: implement action for making selection...
	}
}
